package copyengine.ui.infoTree.buildTree.builder
{
    import copyengine.infoTree.meta.CESDisplayObjectMeta;
    import copyengine.infoTree.meta.CESMovieClipMeta;
    import copyengine.ui.display.movieClip.CEMovieClip;
    import copyengine.ui.display.movieClip.CEMovieClipChild;
    import copyengine.ui.infoTree.buildTree.InfoTreeBuildUtils;
    import copyengine.utils.CEStringUtils;

    import flash.utils.Dictionary;

    import starling.display.DisplayObject;

    public class InfoTreeBuilderMovieClip extends InfoTreeBuilderBasic
    {
        public function InfoTreeBuilderMovieClip()
        {
            super();
        }

        override public function isCanHandleMeta(_meta:*):Boolean {return _meta is CESMovieClipMeta;}

        override public function getBuildResultMc(_meta:*, _quickFindDic:Dictionary, _quickFindKeyPR:String, _isRoot:Boolean):DisplayObject
        {
            var allMovieClipChildMcVector:Vector.<CEMovieClipChild> = new Vector.<CEMovieClipChild>();

            var meta:CESMovieClipMeta = _meta as CESMovieClipMeta;
            var totalNumChildLength:int = meta.allTargetMetaArray.length;
            InfoTreeBuildUtils.sortContainerSubChild(meta.allTargetMetaArray);

            var childQuickPR:String;
            var childQuickFindDic:Dictionary;
            if (_isRoot) {
                childQuickPR = "root";
                childQuickFindDic = _quickFindDic;
            } else {
                childQuickPR = _quickFindKeyPR + "[" + meta.name + "]";
                childQuickFindDic = CEStringUtils.beginsWith(meta.name, "instance") == true ? null : _quickFindDic;
            }

            for (var i:int = 0; i < totalNumChildLength; i++) {
                var eachChildMeta:CESDisplayObjectMeta = meta.allTargetMetaArray[i];
                var childMc:DisplayObject = mBuildHelper.getBuilderByMeta(eachChildMeta).getBuildResultMc(eachChildMeta, childQuickFindDic, childQuickPR, false);
                if (childMc != null) {
                    //Node节点为Meta对象 不含有显示信息
                    var movieClipChild:CEMovieClipChild = new CEMovieClipChild();
                    movieClipChild.initialzie(childMc, eachChildMeta);
                    allMovieClipChildMcVector.push(movieClipChild);
                }
            }

            var resultMc:CEMovieClip = new CEMovieClip(meta, allMovieClipChildMcVector);
            InfoTreeBuildUtils.setBasicInfoByMeta(meta, resultMc);
            InfoTreeBuildUtils.addToQuickFindDic(resultMc, _quickFindDic, _quickFindKeyPR, _isRoot);

            return resultMc;
        }
    }
}
